package com.atguigu04.set;

import com.sun.source.tree.Tree;
import org.junit.Test;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * ClassName: TreeSetTest
 * Package: com.atguigu04.set
 * Description:
 *
 * @Author BuTang
 * @Create 2023/6/7 10:29
 * @Version 1.0
 */
public class TreeSetTest {
    @Test
    public void test1(){

        //定制排序
        Comparator com = new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                if (o1 instanceof String && o2 instanceof String) {
                    String s1 = (String) o1;
                    String s2 = (String) o2;
                    if(o1 == o2 ) return 0;
                    if (s1.length() > s2.length() )return -1;
                    if (s1.length() < s2.length() )return 1;

                }
                throw new RuntimeException("类型错误");
            }
        };

        Set set = new TreeSet(com);
        set.add("我");
        set.add("我我");
        set.add("我我我我我我我");
        set.add("我我我");
        set.add("我我我我我");

        System.out.println(set);
    }
}
